import { createRouter, createWebHistory ,createWebHashHistory} from 'vue-router'
import HomeViewVue from '@/views/HomeView.vue'
import { containsProp } from '@vueuse/shared'

import navList from '@/utils/navList.js'
// 导入store仓库
import store from "@/stores"


// 导入npprogress进度条
import Nprogress from "nprogress"
import "nprogress/nprogress.css"


const router = createRouter({
  // history: createWebHistory(import.meta.env.BASE_URL),
  history: createWebHashHistory(import.meta.env.BASE_URL), //hash模式
  routes: [
    {
      path:'/',
      redirect:"/home",
    },
    {
      path:'/home',
      name:'home',
      component:HomeViewVue,
      children:[
        {
          path:"users",
          name:"users",
          component:()=>import('@/views/users/UsersView.vue')
        },
        {
          path:"roles",
          name:'roles',
          component:()=>import('@/views/roles/RolesView.vue')
        },
        // 权限列表
        {
          path:'rights',
          name:'rights',
          component:()=>import('../views/rights/RightsView.vue')
        },
        // 商品列表
        {
          path:'goods',
          name:'goods',
          component:()=>import('../views/goods/GoodsView.vue')
        },
        // 分类参数
        {
          path:'catas',
          name:'catas',
          component:()=>import('../views/catas/CatasView.vue')
        },
        // 商品分类
        {
          path:'goodscata',
          name:'goodscata',
          component:()=>import('../views/goods/GoodsCataView.vue')
        },
        // 商品参数
        {
          path:'goodsargs',
          name:'goodsargs',
          component:()=>import('../views/goods/GoodsArgs.vue')
        },
        // 订单列表
        {
          path:'orders',
          name:'orders',
          component:()=>import('../views/orders/OrdersView.vue')
        },
        // 数据统计
        {
          path:'report',
          name:'report',
          component:()=>import('../views/reports/ReportView.vue')
        }
        //  ....二级路由
      ]
    },
    {
      path:'/login',
      name:'login',
      component:()=>import('@/views/LoginView.vue')
    }
    
  ]
})


// 路由全局前置守卫
router.beforeEach((to,from,next)=>{

  // 启动进度条
  Nprogress.start()


  console.log(to.name)
  console.log(navList[to.name])   //数组
  // 把面包屑的导航信息存储在本地 或者vuex
  // localStorage.setItem('navlist',JSON.stringify(navList[to.name]))  
  // 存储到vuex中
  store.commit('setNavList',navList[to.name])


  next()

})

router.afterEach((to,from)=>{
  // 结束进度条
  Nprogress.done()

})



export default router
